from gtug import models
import settings

def startup():
    
    output = {'profile': 0, 'admin': 0, 'post': 0}
    
    profile = models.Profile.objects.all().count()
    admin = models.User.get_admins().count()
    category = models.Category.objects.all().count()
    
    
    """ valida perfil """
    if profile != 3:
        models.Profile.start_values()
    
    
    """ valida admin """
    if admin == 0:
        
        for p in settings.ADMINS:
            u = models.User(name=p[0], email=p[1])
            p = models.Profile.gql('WHERE name=:1', 'ADMIN').get()
            u.profile = p
            
            # save
            u.put()
            
    
    """ valida categorias """
    if category == 0:
        for cat in settings.STANDARD_CATEGORIES:
            c = models.Category(path='', title=cat[0], keywords=cat[1], description=cat[2], body=' ')
            c.put()
        